package lagou.homework.lagou_homework_rocketmq.handler;

import lagou.homework.lagou_homework_rocketmq.common.ResponseResult;
import lagou.homework.lagou_homework_rocketmq.exception.SeckillException;
import lagou.homework.lagou_homework_rocketmq.utils.Response;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 认证异常
     * @param e
     * @return
     */
    @ExceptionHandler(SeckillException.class)
    @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
    public ResponseResult seckillExction(SeckillException e) {
        return Response.fail(e);
    }

    /**
     *
     * @param e 未知异常捕获
     * @return
     */
    @ExceptionHandler(Exception.class)
    @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
    public ResponseResult UnNoException(Exception e) {
        return Response.fail(e);
    }
}
